package com.tang.studentinformationmanagementsystem.controller;


import com.tang.studentinformationmanagementsystem.pojo.ClaQueryParam;
import com.tang.studentinformationmanagementsystem.pojo.Clazz;
import com.tang.studentinformationmanagementsystem.pojo.PageResult;
import com.tang.studentinformationmanagementsystem.pojo.Result;
import com.tang.studentinformationmanagementsystem.service.ClaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clazzs")
public class ClaController {
    @Autowired
    private ClaService claService;

    //分页查询
    @GetMapping
    public Result page(ClaQueryParam claQueryParam){
        PageResult pageResult=claService.page(claQueryParam);
        return Result.success(pageResult);
    }

    //查询单个
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        Clazz byId = claService.getById(id);
        return Result.success(byId);
    }

    //查询所有
    @GetMapping("/list")
    public Result list(){
        return Result.success(claService.findAll());
    }

    //添加
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        claService.save(clazz);
        return Result.success();
    }
    //修改
    @PutMapping
    public  Result update(@RequestBody Clazz clazz){
        claService.save(clazz);
        return Result.success();
    }

    //删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        claService.deleteById(id);
        return Result.success();
    }
}
